package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mapper.OptionsMapper;
import com.tanhua.model.db.Option;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OptionsApiImpl implements OptionsApi {

    @Autowired
    private OptionsMapper optionsMapper;

    // 根据问题id查询选项
    @Override
    public List<Option> selectOptions(Integer questionId) {

        // 指定查询条件
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("questionId",questionId);

        // 查询
        List<Option> optionList = optionsMapper.selectList(queryWrapper);
        return optionList;
    }

    // 根据问题id删除对应的选项
    @Override
    public void deleteByQuestionId(Integer questionId) {

        // 指定删除条件
        QueryWrapper<Option> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("questionId",questionId);

        // 删除
        optionsMapper.delete(queryWrapper);
    }

    // 保存选项
    @Override
    public void saveOption(Option option) {

        optionsMapper.insert(option);
    }
}
